package com.example.d10_homework.homework01;

public class Account {
    private double balance;

    public Account() {
    }

    public Account(double balance) {
        this.balance = balance;
    }

    // 存钱方法
    // 使用同步方法
    /*public synchronized void deposit(double money) {
        if (money > 0) {
            balance += money;
            System.out.println(Thread.currentThread().getName() + ":存钱成功,余额为：" + balance);
        }
    }*/

    // 使用同步代码块
    public void deposit(double money) {
        synchronized (this) {
            if (money > 0) {
                balance += money;
                System.out.println(Thread.currentThread().getName() + ":存钱成功,余额为：" + balance);
            }
        }
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }
}
